package edu.msu.cse.meldru20.project1;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

public class FinalScoreActivity extends Activity {

	private GameManager game = null;	
	private TextView player1score, player2score, winner;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_final_score);
		game = GameManager.get();
		
		
		player1score = (TextView)findViewById(R.id.textViewPlayer1);
		player2score = (TextView)findViewById(R.id.textViewPlayer2);
		winner = (TextView)findViewById(R.id.textViewWinner);
		
		player1score.setText(game.getPlayer1() + ": " + game.getPlayer1Score());
		player2score.setText(game.getPlayer2() + ": " + game.getPlayer2Score());
		
		if(game.getPlayer1Score() > game.getPlayer2Score()) {
			winner.setText(game.getPlayer1() + " Wins!!!");
		}
		else if(game.getPlayer1Score() < game.getPlayer2Score()) {
			winner.setText(game.getPlayer2() + " Wins!!!");
		}
		else {
			winner.setText("Draw Game");
		}
	}

	public void onFinish(View view) {
		// Need to reset the game manager
		game.Init();
		
		
		// Return to the main menu
		Intent intent = new Intent(this, MainActivity.class);
		intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
		startActivity(intent);
	}

}
